package com.jinken._04delay;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.List;

/**
 * 生产者
 */
public class Producer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        //创建生产者对象
        DefaultMQProducer dmp = new DefaultMQProducer("delay_group1");
        //设置NamseServer地址
        dmp.setNamesrvAddr("192.168.126.100:9876");


        //启动生产者
        dmp.start();
        //创建消息对象
        Message message = new Message("delay_topic1","","这是延时消息".getBytes());

        //设置延时
        //设置延时级别
        //1到18分别对应messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
        //message.setDelayTimeLevel(3);
        //设置自定义时间
        message.setDelayTimeSec(10);

        //发送消息
        dmp.send(message);

        //关闭生产者
        dmp.shutdown();
    }


}
